* this script removes irrelevant corporate owners found via search in SReg
* these owners include state agencies, depositories/custodians, stock exchanges, brokerages, NGOs, charities, soccer clubs, etc. 
use owners_from_SReg, clear
keep if entity==1

* define dummies for different types of irrelevant owners based on identifiers
if _N > 0 {
* state agencies
gen state=.
replace state=1 if country==804 & id==35642
replace state=1 if id<=32997 & country==804
replace state=1 if id==19442 & country==804
replace state=1 if country==804 & id==32997
replace state=1 if country==804 & id==13511245 
replace state=1 if country==804 & id==13467337 
replace state=1 if country==804 & id==13347870
replace state=1 if country==804 & id==4052784 
replace state=1 if country==804 & id==4052092
replace state=1 if country==804 & id==20495280
replace state=1 if country==804 & id==2070915
replace state=1 if country==804 & id==36860
replace state=1 if country==804 & id==13747462
replace state=1 if country==804 & id==19028107
replace state=1 if country==804 & id==20823070
replace state=1 if country==804 & id==21124686
replace state=1 if country==804 & id==32945
replace state=1 if country==804 & id==23193929
replace state=1 if country==804 & id==2140892
replace state=1 if country==804 & id==734373
replace state=1 if country==804 & id==4057942
replace state=1 if country==804 & id==14005581
replace state=1 if country==804 & id==4526457
replace state=1 if country==804 & id==34045
replace state=1 if country==804 & id==2574165
replace state=1 if country==804 & id==22094295
replace state=1 if country==804 & id==4052844
replace state=1 if country==804 & id==4053051
replace state=1 if country==804 & id==4052815
replace state=1 if country==804 & id==4055914
replace state=1 if country==804 & id==13349490
replace state=1 if country==804 & id==13649370
replace state=1 if country==804 & id==4860627
replace state=1 if country==804 & id==5833667
replace state=1 if country==804 & id==24068072
replace state=1 if country==804 & id==701412
replace state=1 if country==804 & id==2934356
replace state=1 if country==804 & id==22027241
replace state=1 if country==804 & id==4054553
replace state=1 if country==804 & id==21713460
replace state=1 if country==804 & id==9325703
replace state=1 if country==804 & id==958140
replace state=1 if country==804 & id==4052889
replace state=1 if country==804 & id==2944886
replace state=1 if country==804 & id==2070890
replace state=1 if country==804 & id==25932851
replace state=1 if country==804 & id==23328074
replace state=1 if country==804 & id==20525153
replace state=1 if country==804 & id==4057043
replace state=1 if country==804 & id==3451536
replace state=1 if country==804 & id==23243231
replace state=1 if country==804 & id==22112642
replace state=1 if country==804 & id==20812415
replace state=1 if country==804 & id==4056919
replace state=1 if country==804 & id==20432380
replace state=1 if country==804 & id==21368158
replace state=1 if country==804 & id==22642124
replace state=1 if country==804 & id==9336345
replace state=1 if country==804 & id==4053832
replace state=1 if country==804 & id==3445665
replace state=1 if country==804 & id==24503042
replace state=1 if country==804 & id==25829550
replace state=1 if country==804 & id==230480
replace state=1 if country==804 & id==4398882
replace state=1 if country==804 & id==24946503
replace state=1 if country==804 & id==24411541
replace state=1 if country==804 & id==13576948
replace state=1 if country==804 & id==13467337
replace state=1 if country==804 & id==24812116
replace state=1 if country==804 & id==24958630
replace state=1 if country==804 & id==13238
replace state=1 if country==804 & id==41482
replace state=1 if country==804 & id==22286899
replace state=1 if country==804 & id==23205029
replace state=1 if country==804 & id==62857
replace state=1 if country==804 & id==701613
replace state=1 if country==804 & id==730980
replace state=1 if country==804 & id==732973
replace state=1 if country==804 & id==915202
replace state=1 if country==804 & id==1044985
replace state=1 if country==804 & id==13578893
replace state=1 if country==804 & id==2550006
replace state=1 if country==804 & id==9321020
replace state=1 if country==804 & id==24740635
replace state=1 if country==804 & id==3365860
replace state=1 if country==804 & id==21149445
replace state=1 if country==804 & strpos(name, "ФОНДУ ДЕРЖАВНОГО МАЙНА")
replace state=1 if country==804 & strpos(name, "МІСЬКА РАДА")
replace state=1 if country==804 & strpos(name, "РАЙОННА ДЕРЖАВНА АДМIНIСТРАЦIЯ")
replace state=1 if country==804 & strpos(name, "ВИКОНАВЧИЙ КОМIТЕТ")
replace state=1 if country==804 & strpos(name, "ДЕРЖАВНА АДМІНІСТРАЦІЯ")
replace state=1 if country==804 & strpos(name, "МІСЬКОЇ РАДИ")
replace state=1 if country==804 & id==8592193
replace state=1 if country==804 & id==33833561
replace state=1 if country==804 & id==20866865

* investment funds
gen inv=.
replace inv=1 if country==804 & id==23908452
replace inv=1 if country==804 & id==23380927
replace inv=1 if country==804 & id==32494301
replace inv=1 if country==804 & id==23461057
replace inv=1 if country==804 & id==21626241
replace inv=1 if country==804 & id==20525974
replace inv=1 if country==804 & id==20364448
replace inv=1 if country==804 & id==20363673
replace inv=1 if country==804 & id==21561286
replace inv=1 if country==804 & id==22334753
replace inv=1 if country==804 & id==22646843
replace inv=1 if country==804 & id==23853679
replace inv=1 if country==804 & id==23754658
replace inv=1 if country==804 & id==13485789
replace inv=1 if country==804 & id==22930811
replace inv=1 if country==804 & id==23604396
replace inv=1 if country==804 & id==24084214
replace inv=1 if country==804 & id==23456808
replace inv=1 if country==804 & id==21982450
replace inv=1 if country==804 & id==23462298
replace inv=1 if country==804 & id==30623316
replace inv=1 if country==804 & id==36359
replace inv=1 if country==804 & id==16461855
replace inv=1 if country==804 & id==22859622
replace inv=1 if country==804 & id==13317856
replace inv=1 if country==804 & id==20288291
replace inv=1 if country==804 & id==20375819
replace inv=1 if country==804 & id==13490081
replace inv=1 if country==804 & id==29671
replace inv=1 if country==804 & id==20368541
replace inv=1 if country==804 & id==21465022
replace inv=1 if country==804 & id==22012529
replace inv=1 if country==804 & id==22347945
replace inv=1 if country==804 & id==20542223
replace inv=1 if country==804 & id==21626382
replace inv=1 if country==804 & id==21041115
replace inv=1 if country==804 & id==23763172
replace inv=1 if country==804 & id==20337279
replace inv=1 if country==804 & id==23386516
replace inv=1 if country==804 & id==23439000
replace inv=1 if country==804 & id==20723887
replace inv=1 if country==804 & id==23386315
replace inv=1 if country==804 & id==22858717
replace inv=1 if country==804 & id==24820699
replace inv=1 if country==804 & id==20036655
replace inv=1 if country==804 & id==32169437
replace inv=1 if country==804 & id==31865193
replace inv=1 if country==804 & id==23358460
replace inv=1 if country==804 & id==21568727
replace inv=1 if country==804 & id==24533037
replace inv=1 if country==804 & id==3445665
replace inv=1 if country==804 & id==25339998
replace inv=1 if country==804 & id==24466246
replace inv=1 if country==804 & id==13728269
replace inv=1 if country==804 & id==19467508
replace inv=1 if country==804 & id==22968558
replace inv=1 if country==804 & id==24275018
replace inv=1 if country==804 & id==23146812
replace inv=1 if country==804 & id==21648283
replace inv=1 if country==804 & id==21810772
replace inv=1 if country==804 & id==21629417
replace inv=1 if country==804 & id==23468993
replace inv=1 if country==804 & id==21639545
replace inv=1 if country==804 & id==23505754
replace inv=1 if country==804 & id==32281409
replace inv=1 if country==804 & id==32486458
replace inv=1 if country==804 & id==32523934
replace inv=1 if country==804 & id==32439633
replace inv=1 if country==804 & id==25580895
replace inv=1 if country==804 & id==31255142
replace inv=1 if country==804 & id==32708129
replace inv=1 if country==804 & id==31259063
replace inv=1 if country==804 & id==31113268
replace inv=1 if country==804 & id==32335917
replace inv=1 if country==804 & id==20115415
replace inv=1 if country==804 & id==23155739
replace inv=1 if country==804 & id==30971831
replace inv=1 if country==804 & id==20068738
replace inv=1 if country==804 & id==31063268
replace inv=1 if country==804 & id==23399476
replace inv=1 if country==804 & id==31809521
replace inv=1 if country==804 & id==25943197
replace inv=1 if country==804 & id==22904759
replace inv=1 if country==804 & id==31556656
replace inv=1 if country==804 & id==20930497
replace inv=1 if country==804 & id==23377167
replace inv=1 if country==804 & id==22904759
replace inv=1 if country==804 & id==23399476
replace inv=1 if country==804 & id==23927515
replace inv=1 if country==804 & id==32710384
replace inv=1 if country==804 & id==32523934
replace inv=1 if country==804 & id==32439633
replace inv=1 if country==804 & id==25580895
replace inv=1 if country==804 & id==23062245
replace inv=1 if country==804 & id==22928103
replace inv=1 if country==804 & strpos(name, "IНВЕСТИЦIЙНИЙ ФОНД")
replace inv=1 if country==804 & strpos(name, "ІНВЕСТИЦІЙНИЙ ФОНД")
replace inv=1 if country==804 & strpos(name, "IНВЕСТИЦIЙНА КОМПАНIЯ")
replace inv=1 if country==804 & id==21871383
replace inv=1 if country==804 & id==22236097
replace inv=1 if country==804 & id==23319448
replace inv=1 if country==804 & id==23332578
replace inv=1 if country==804 & id==23332584
replace inv=1 if country==804 & id==23517763
replace inv=1 if country==804 & id==23523692
replace inv=1 if country==804 & id==24253303
replace inv=1 if country==804 & id==32589576
replace inv=1 if country==804 & id==32762055
replace inv=1 if country==804 & id==20686637
replace inv=1 if country==804 & id==20724154
replace inv=1 if country==804 & id==23597182
replace inv=1 if country==804 & id==32335917
replace inv=1 if country==804 & id==25218409
replace inv=1 if country==804 & id==32710384
replace inv=1 if country==804 & id==25580895

* unions/associations
gen union=.
replace union=1 if country==804 & id==23703916
replace union=1 if country==804 & id==13463115
replace union=1 if country==804 & id==1355604
replace union=1 if country==804 & id==14290993
replace union=1 if country==804 & id==14297558
replace union=1 if country==804 & id==16327625
replace union=1 if country==804 & id==1740911
replace union=1 if country==804 & id==174800
replace union=1 if country==804 & id==1778150
replace union=1 if country==804 & id==191307
replace union=1 if country==804 & id==20499792
replace union=1 if country==804 & id==20800783
replace union=1 if country==804 & id==20812415
replace union=1 if country==804 & id==21593493
replace union=1 if country==804 & id==21655159
replace union=1 if country==804 & id==21729337
replace union=1 if country==804 & id==21948140
replace union=1 if country==804 & id==22063685
replace union=1 if country==804 & id==22281229
replace union=1 if country==804 & id==22374639
replace union=1 if country==804 & id==22453771
replace union=1 if country==804 & id==23954765
replace union=1 if country==804 & id==24089944
replace union=1 if country==804 & id==24779063
replace union=1 if country==804 & id==24820699
replace union=1 if country==804 & id==2605150
replace union=1 if country==804 & id==2657862
replace union=1 if country==804 & id==2658850
replace union=1 if country==804 & id==2659217
replace union=1 if country==804 & id==2665867
replace union=1 if country==804 & id==2675268
replace union=1 if country==804 & id==2893019
replace union=1 if country==804 & id==30441567
replace union=1 if country==804 & id==30874076
replace union=1 if country==804 & id==3087800
replace union=1 if country==804 & id==3088053
replace union=1 if country==804 & id==31889937
replace union=1 if country==804 & id==32087695
replace union=1 if country==804 & id==3364607
replace union=1 if country==804 & id==3452814
replace union=1 if country==804 & id==3586650
replace union=1 if country==804 & id==374019
replace union=1 if country==804 & id==3758571
replace union=1 if country==804 & id==3760987
replace union=1 if country==804 & id==453049
replace union=1 if country==804 & id==4542672
replace union=1 if country==804 & id==4634552
replace union=1 if country==804 & id==4851189
replace union=1 if country==804 & id==5446700
replace union=1 if country==804 & id==5798014
replace union=1 if country==804 & id==702067
replace union=1 if country==804 & id==25114839
replace union=1 if country==804 & id==22612382
replace union=1 if country==804 & id==13966359
replace union=1 if country==804 & id==174800
replace union=1 if country==804 & id==20063014
replace union=1 if country==804 & id==30075379
replace union=1 if country==804 & id==21593493
replace union=1 if country==804 & id==453285
replace union=1 if country==804 & id==20923712
replace union=1 if country==804 & id==31906627
replace union=1 if country==804 & id==32091240
replace union=1 if country==804 & id==21388557
replace union=1 if country==804 & id==20124773
replace union=1 if country==804 & id==24914779
replace union=1 if country==804 & id==23385445
replace union=1 if country==804 & id==25624768
replace union=1 if country==804 & id==24006757
replace union=1 if country==804 & id==21685491
replace union=1 if country==804 & id==14295913
replace union=1 if country==804 & id==13671397
replace union=1 if country==804 & id==2606362
replace union=1 if country==804 & id==2605204
replace union=1 if country==804 & id==1035621
replace union=1 if country==804 & id==466164
replace union=1 if country==804 & id==14479
replace union=1 if country==804 & id==36897
replace union=1 if country==804 & id==453351
replace union=1 if country==804 & id==14360357
replace union=1 if country==804 & id==463131
replace union=1 if country==804 & id==848138
replace union=1 if country==804 & id==32091240
replace union=1 if country==804 & id==1044985
replace union=1 if country==804 & id==3081460
replace union=1 if country==804 & id==20097616
replace union=1 if country==804 & id==22049320
replace union=1 if country==804 & id==2659370
replace union=1 if country==804 & id==21958530
replace union=1 if country==804 & id==697550
replace union=1 if country==804 & id==20064315
replace union=1 if country==804 & id==3451826
replace union=1 if country==804 & id==22506622
replace union=1 if country==804 & id==20245904
replace union=1 if country==804 & id==23243892
replace union=1 if country==804 & id==25662357
replace union=1 if country==804 & id==20618216
replace union=1 if country==804 & id==5510303
replace union=1 if country==804 & id==22883495
replace union=1 if country==804 & id==24853546
replace union=1 if country==804 & id==16307261
replace union=1 if country==804 & id==22923277
replace union=1 if country==804 & id==30100441
replace union=1 if country==804 & id==13322745
replace union=1 if country==804 & id==13486292
replace union=1 if country==804 & id==5581272
replace union=1 if country==804 & id==14023826
replace union=1 if country==804 & id==4540762
replace union=1 if country==804 & id==25662357
replace union=1 if country==804 & id==191804
replace union=1 if country==804 & id==24748186
replace union=1 if country==804 & id==23243892
replace union=1 if strpos(name, "АСОЦІАЦІЯ")
replace union=1 if strpos(name, "ПРОФСПIЛКИ")
replace union=1 if country==804 & id==23294180
replace union=1 if country==804 & id==19486548
replace union=1 if country==804 & id==19486548

* stock/commodity exchanges
gen birzha=.
replace birzha=1 if country==804 & id==24257656
replace birzha=1 if country==804 & id==34864
replace birzha=1 if country==804 & id==25158707
replace birzha=1 if country==804 & id==22877057
replace birzha=1 if country==804 & id==23364874
replace birzha=1 if country==804 & id==32325959
replace birzha=1 if country==804 & id==31127841
replace birzha=1 if country==804 & id==25535920
replace birzha=1 if country==804 & id==23243248
replace birzha=1 if country==804 & id==23425110
replace birzha=1 if country==804 & id==24397456
replace birzha=1 if country==804 & id==23331780
replace birzha=1 if country==804 & id==14281095
replace birzha=1 if country==804 & id==24917996
replace birzha=1 if country==804 & id==30554892
replace birzha=1 if country==804 & id==20332000
replace birzha=1 if country==804 & id==24466246
replace birzha=1 if country==804 & id==25339998
replace birzha=1 if country==804 & id==24257656
replace birzha=1 if country==804 & id==30057700
replace birzha=1 if country==804 & id==16286412
replace birzha=1 if country==804 & id==25587035
replace birzha=1 if country==804 & id==21594038
replace birzha=1 if country==804 & id==24350147
replace birzha=1 if country==804 & id==30736919
replace birzha=1 if country==804 & id==25369156
replace birzha=1 if country==804 & id==22858255
replace birzha=1 if country==804 & id==14281095
replace birzha=1 if country==804 & id==22861932
replace birzha=1 if country==804 & id==22338923
replace birzha=1 if country==804 & id==23513038
replace birzha=1 if country==804 & id==20115415
replace birzha=1 if country==804 & id==23155739
replace birzha=1 if country==804 & id==20068738
replace birzha=1 if country==804 & id==24778589
replace birzha=1 if country==804 & id==25901112
replace birzha=1 if country==804 & id==24056962
replace birzha=1 if country==804 & id==25340553
replace birzha=1 if country==804 & id==21653380
replace birzha=1 if country==804 & id==23467723
replace birzha=1 if country==804 & id==23590760
replace birzha=1 if country==804 & id==25675153
replace birzha=1 if country==804 & id==30106752
replace birzha=1 if country==804 & id==30220318
replace birzha=1 if country==804 & id==13298478
replace birzha=1 if country==804 & id==20064500
replace birzha=1 if country==804 & strpos(name, "БІРЖА")

* brokerages
replace birzha=1 if country==804 & id==13446660
replace birzha=1 if country==804 & id==23704123
replace birzha=1 if country==804 & id==23728336
replace birzha=1 if country==804 & id==32436077

* NGOs
gen ngo=.
replace ngo=1 if country==804 & id==26020610
replace ngo=1 if country==804 & id==5540037
replace ngo=1 if country==804 & id==5402565
replace ngo=1 if country==804 & id==21176743
replace ngo=1 if country==804 & id==20350535
replace ngo=1 if country==804 & id==174094
replace ngo=1 if country==804 & id==21954123
replace ngo=1 if country==804 & id==188311
replace ngo=1 if country==804 & id==5411357
replace ngo=1 if country==804 & id==5420557
replace ngo=1 if country==804 & id==2095826
replace ngo=1 if country==804 & id==20204271
replace ngo=1 if country==804 & id==5496135
replace ngo=1 if country==804 & id==2543472
replace ngo=1 if country==804 & id==65175
replace ngo=1 if country==804 & id==22719803
replace ngo=1 if country==804 & id==2070921
replace ngo=1 if country==804 & id==26020610
replace ngo=1 if country==804 & id==25445186
replace ngo=1 if country==804 & id==25687883
replace ngo=1 if country==804 & id==30359792
replace ngo=1 if country==804 & id==22932046
replace ngo=1 if country==804 & id==35895
replace ngo=1 if country==804 & id==25192549
replace ngo=1 if country==804 & id==25884804
replace ngo=1 if country==804 & id==25967387
replace ngo=1 if country==804 & id==30210907
replace ngo=1 if country==804 & id==25604420
replace ngo=1 if strpos(name, "ГРОМАДСЬКА ОРГАНІЗАЦІЯ")
replace ngo=1 if country==804 & id==14280492

* soccer clubs
gen socc=.
replace socc=1 if country==804 & id==305981
replace socc=1 if country==804 & id==35145
replace socc=1 if country==804 & id==169816
replace socc=1 if country==804 & id==23768175
replace socc=1 if country==804 & id==14238248
replace socc=1 if country==804 & id==24440560
replace socc=1 if country==804 & id==31916221
replace socc=1 if country==804 & id==14242741
replace socc=1 if country==804 & id==305981
replace socc=1 if country==804 & id==13728269
replace socc=1 if country==804 & strpos(name, "ФУТБОЛ")
replace socc=1 if country==804 & id==24440560

* consumer and other unions
gen cunion=1 if strpos(name, "СПОЖИВЧЕ ТОВАРИСТВО")
replace cunion=1 if strpos(name, "СПІЛКА СПОЖИВЧИХ")
replace cunion=1 if strpos(name, "ТРУДОВИЙ КОЛЕКТИВ")
replace cunion=1 if strpos(name, "СПОЖИВЧА СПIЛКА")
replace cunion=1 if strpos(name, "СПIЛКА СПОЖИВЧИХ ТОВАРИСТВ")
replace cunion=1 if strpos(name, "СПОЖИВЧИХ ТОВАРИСТВ")
replace cunion=1 if strpos(name, "РАЙОННОГО СПОЖИВЧОГО ТОВАРИСТВА")
replace cunion=1 if strpos(name, "ОБЛСПОЖИВСПIЛКИ")
replace cunion=1 if strpos(name, "СПIЛКИ СПОЖИВЧИХ ТОВАРИСТ")
replace cunion=1 if strpos(name, "УКООПСПIЛКИ")
replace cunion=1 if country==804 & id==1744286
replace cunion=1 if country==804 & id==1744760
replace cunion=1 if country==804 & id==1748686
replace cunion=1 if country==804 & id==1758087
replace cunion=1 if country==804 & id==1758762
replace cunion=1 if country==804 & id==1708959
replace cunion=1 if country==804 & id==1559123
replace cunion=1 if country==804 & id==1752914

* check dummies
tab state
tab inv
tab birzha
tab ngo
tab union
tab socc
tab cunion

* drop irrelevant owners
drop if state==1 | inv==1 | birzha==1 | ngo==1 | union==1 | socc==1 | cunion==1
drop if id==0
* missing names in SReg
drop if id==88093 | id==13535205 | id==30340907

* drop temporary variables
drop state inv birzha ngo union socc cunion

*drop duplicates in terms of owner-firm pairs
sort id prev_id country
quietly by id prev_id country: gen dup = cond(_N==1,0,_n) 
drop if dup>1 & id!=0
drop dup
}

* save data
save owners_from_SReg_clean_corporate.dta, replace
